package prv.pursuivant.config.impl;

import prv.pursuivant.config.CategoryDesc;
import prv.pursuivant.config.ConfigSerializer;
import prv.pursuivant.config.ImporterDesc;
import prv.pursuivant.core.impl.ToonImpl;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * Factory class to instantiate XStream serializers
 * 
 * @author Kwinto
 */
public class XStreamConfigSerializerModule extends AbstractModule {

	@Provides
	XStream provideXStream() {
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("config", ConfigImpl.class);
		xstream.alias("toon", ToonImpl.class);
		xstream.addDefaultImplementation(CategoryDescImpl.class,
				CategoryDesc.class);
		xstream.addDefaultImplementation(ImporterDescImpl.class,
				ImporterDesc.class);
//		xstream.aliasField("achievement", ConfigImpl.class, "activeAchievements");
//		xstream.addImplicitCollection(ConfigImpl.class, "activeAchievements", "achievement", String.class);
		xstream.alias("achievement", AchievTypeId.class);
		xstream.omitField(ConfigImpl.class, "achievements");
		xstream.useAttributeFor(String.class);
		xstream.useAttributeFor(Integer.class);
		xstream.useAttributeFor(Boolean.class);
		return xstream;
	}

	@Override
	protected void configure() {
		bind(ConfigSerializer.class).to(XStreamConfigSerializer.class);
	}

}
